package com.effvi.taoke.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.effvi.taoke.admin.ConsoleController;
import com.effvi.taoke.constants.SessionKey;
/**
 * 后台权限拦截器
 * @author Kelvin
 *
 */
public class AccessConsoleInterceptor extends HandlerInterceptorAdapter {
	
	private static Logger logger = Logger.getLogger(AccessConsoleInterceptor.class);
	
	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
		logger.debug("后台访问权限校验");
		HttpSession session = request.getSession();
		Object LoginName = session.getAttribute(SessionKey.ADMIN_LOGIN_NAME);
		if(LoginName != null){
			return super.preHandle(request, response, handler);
		}else{
			response.sendRedirect("/console/login?redirect="+request.getRequestURI());
			return false;
		}
	}

}
